/**
 * 12-会员-供应商-查看编辑详情. <br/>
 *
 * @author fsl gonglong 20151130.
 */
$(function() {

    initPage();

    bindEvent();

});

/**
 * 初始化页面.<br/>
 *
 * @author fsl-gonglong-20151130.
 */
function initPage() {

    // 证件资料
    var paperTempl = _.template($("#paper_templ").html());
    var paperHtml = paperTempl(PAGE_DATA.paperData || []);
    $("#paper-box").html(paperHtml);

    // 认证
    $("#certification").children().each(function(i) {

        $(this).find(":checkbox").prop("checked", (PAGE_DATA.certification[i].chk == "1"));
    });

    // 店铺状态.
    var activeIdx = (PAGE_DATA.storeState == "0") ? 0 : 1;
    $("#sel-recommed").children().eq(activeIdx).addClass("am-btn-success");
    $("#status").val(PAGE_DATA.storeState);

    // 店铺等级.
    adminUtil.getSelectHtml('#store_level', PAGE_DATA.storeLevel || []);
    $("#store_level").val(PAGE_DATA.storeLevelActive || '');

    // 返回.
    $("#back-btn").attr("href", PAGE_DATA.REST_API.backUrl || "");

};

/**
 * 绑定事件.<br/>
 *
 * @author fsl-gonglong-20151130.
 */
function bindEvent() {

    var cssTypes = ["am-btn-default", "am-btn-success"];
    var inputRecommed = $("#status");

    $("#sel-recommed").find("button").on("click", function() {
        $(this).removeClass(cssTypes[0]).addClass(cssTypes[1]);
        $(this).siblings().removeClass(cssTypes[1]).addClass(cssTypes[0]);

        var sts = $(this).attr("data-sts");
        inputRecommed.val(sts);

    });

    // var mainForm = $("#main-form").validate({
    //     rules: {
    //         pw: "required",
    //     }
    // });
};
